package base.interactive.http.impl;

import base.interactive.http.Request;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

/**
 * Https request
 *
 * @description: https请求忽略证书
 * @author: cyj
 * @date 2020 -10-27 14:44:14
 */
@Service
@Slf4j
public class HttpsRequest implements Request {

    /**
     * Rest template
     */
    @Autowired
    @Qualifier("httpsRestTemplate")
    private RestTemplate restTemplate;

    @Override
    public <T> ResponseEntity<T> exchange(String url, HttpMethod httpMethod,
                                          HttpEntity<MultiValueMap<String, String>> request, Class<T> responseType) {
        ResponseEntity<T> responseEntity = restTemplate.exchange(url, httpMethod, request, responseType);
        log.info("https request result:[{}]", responseEntity);
        return responseEntity;
    }
}
